package com.myapplication.interfaces;

import com.myapplication.callback.AddInCartCallback;
import com.myapplication.http.util.HttpFail;
import com.myapplication.http.util.Util;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * Created by zhoushikun on 2016/7/12.
 */
public class AddInCartConnect implements AddInCartInter {
    @Override
    public void addInCart(String goods_id, String quantity, String key, final AddInCartCallback addInCartCallback) {
        RequestParams requestParams = new RequestParams(Util.UrlAddInCart);
        requestParams.addBodyParameter("goods_id",goods_id);
        requestParams.addBodyParameter("quantity",quantity);
        requestParams.addBodyParameter("key",key);
        x.http().post(requestParams, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                addInCartCallback.onAddInCartSuccess(result);
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                addInCartCallback.onAddInCartFail(HttpFail.onError(ex,isOnCallback));
            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }
}
